import type { OrderLogisticResult, OrderPreResult, OrderResult, SubmitOrderParams } from "@/types/order"
import { http } from "@/utils/request"
/**
 * 填写订单-获取预付订单
 * @returns 
 */
export const getOrderPreAPI = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET'
  })
}
/**
 * 填写订单-立即购买
 * @param data  { skuId: string, count: string, addressId?: string }
 * @returns 
 */
export const getOrderPreNowAPI = (data: { skuId: string, count: string, addressId?: string }) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data
  })
}
/**
 * 提交订单
 * @param data 
 * @returns 
 */
export const subMemberOrderAPI = (data: SubmitOrderParams) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data
  })
}
/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderByIdAPI = (id: string) => {
  return http<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`
  })
}
/**
 * 填写订单-再次购买
 * @param id 订单id
 */
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: `/member/order/repurchase/${id}`,
  })
}
/**
 * 模拟发货-内测版
 * @param id 
 * @returns 
 */
export const getOrderConsignmentAPI = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET'
  })
}
/**
 * 模拟支付-内测版
 * @param data 
 * @returns 
 */
export const PayMockAPI = (data: { orderId: string }) => {
  return http({
    url: '/pay/mock',
    method: 'GET',
    data
  })
}
/**
 * 获取微信支付参数
 * @param data 
 * @returns 
 */
export const PayWxPayMiniPayAPI = (data: { orderId: string }) => {
  return http<WechatMiniprogram.RequestCommonPaymentOption>({
    url: '/pay/wxPay/miniPay',
    method: 'GET',
    data
  })
}
/**
 * 确认收货
 * @param id 
 * @returns 
 */
export const putOrderReceiptByIdAPI = (id: string) => {
  return http<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}
/**
 * 获取订单物流
 * @param id 
 * @description  
 */
export const putOrderLogisticsByIdAPI = (id: string) => {
  return http<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}

export const delOrderAPI = (data: { ids: string[] }) => {
  return http({
    url: '/member/order',
    method: 'DELETE',
    data
  })
}